from config.database import db
from datetime import datetime

class Template(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    content = db.Column(db.Text, nullable=False)
    createdAt = db.Column(db.DateTime, default=datetime.utcnow)
    
    def to_dict(self):
        '''实体转字典方法'''
        return {
            "id": self.id,
            "name": self.name,
            "content": self.content,
            "createdAt": self.createdAt.isoformat()
        }